package com.qut.qut_01.controller;

import com.qut.qut_01.mapper.UserMapper;
import org.apache.ibatis.annotations.Insert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

//表示spring框架自动创建对象
//作为控制器使用
@RestController
@RequestMapping("/user")
public class UserController {

    //依赖注入IoC
    @Resource
    private UserMapper userMapper;
    //    完整访问路径； user/reg


    @RequestMapping("/written")
    public int written(@RequestParam Map<String,String> param){
        int row=0;
        System.out.println(param);
        //调用接口中的方法
        row=userMapper.keep(param);
        return row;
    }

    /**
     * Map集合存放每一行中的数据
     * 以列名为key，数据为value
     * userId   userName    userSex
     * 1          张三         2
     * map.put("userId",1);
     * map.put("userName","张三");
     * map.put("userSex",2);
     * @return
     */

    @RequestMapping("/search_1")
    public List<Map<String ,Object>> search_1(@RequestParam Map<String,Object> param){
        List<Map<String,Object>> list=null;
        list=userMapper.search_1(param);
        return list;
    }



    @RequestMapping("/Edit")
    public int Edit(@RequestParam Map<String,String> param)
    {
        int row=0;
        row=userMapper.update(param);
        return row;
    }

    @RequestMapping("/delete")
    public int batchDelete(String[] ids){
        int row=0;
        System.out.println(Arrays.toString(ids));
        row=userMapper.batchDelete(ids);
        return row;
    }
}